package com.andy.blog.admin.service.impl;

import com.andy.blog.admin.dto.SysLoginLogDTO;
import com.andy.blog.admin.service.SysLoginLogBusService;
import com.andy.blog.common.page.PageUtilsDTO;
import com.andy.blog.common.utils.TransformUtils;
import com.andy.blog.dal.domain.SysLoginLogDO;
import com.andy.blog.dal.service.SysLoginLogDalService;
import com.andy.blog.dal.vo.SysLoginLogVO;
import com.andy.blog.framework.web.service.SysPasswordService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by andy on 2023/4/20 17:41
 */
@Service
public class SysLoginLogBusServiceImpl implements SysLoginLogBusService {

    @Resource
    private SysLoginLogDalService loginLogDalService;

    @Resource
    private SysPasswordService passwordService;


    @Override
    public PageUtilsDTO<SysLoginLogDTO> selectListByPage(SysLoginLogVO sysLoginLogVO) {
        IPage<SysLoginLogDO> page = loginLogDalService.selectListByPage(sysLoginLogVO);
        return PageUtilsDTO.build(page.getTotal(), TransformUtils.transformList(page.getRecords(), SysLoginLogDTO.class));
    }

    @Override
    public List<SysLoginLogDTO> selectListByCondition(SysLoginLogVO sysLoginLogVO) {
        List<SysLoginLogDO> sysLoginLogDOS = loginLogDalService.selectListByCondition(sysLoginLogVO);
        return TransformUtils.transformList(sysLoginLogDOS, SysLoginLogDTO.class);
    }

    @Override
    public void deleteByIds(List<Long> ids) {
        loginLogDalService.deleteByIds(ids);
    }

    @Override
    public void clean() {
        loginLogDalService.cleanLoginLog();
    }

    @Override
    public void clearLoginRecordCache(String userName) {
        passwordService.clearLoginRecordCache(userName);
    }
}
